home *** CD-ROM | disk | FTP | other *** search
- #include <suntool/sunview.h>
- #include <suntool/canvas.h>
- #include <suntool/panel.h>
- #include <stdio.h>
- #include "defs.h"
-
- #define WINLEVFONT "/usr/lib/fonts/fixedwidthfonts/cour.r.16"
- #define XSIZE 256
- #define YSIZE 256
-
- har *progname;
-
- tatic short winicon[] =
- {
- #include "../images/icons/winlev8.icon"
- };
-
- EFINE_ICON_FROM_IMAGE(icon, winicon);
-
- nt boxsize = 2;
- tatic void getcoords(), repaint_canvas(), invert_proc(), colour_proc(), quit_proc(), reset_proc();
- nt invert = 0;
- nt colour = 0;
- nt base = 20;
- nt window = 255, level = 127;
- har *progname;
-
- Frame frame;
- anvas canvas, canvas2;
- anel panel, inv_panel, col_panel;
- ixfont *font;
- ixwin *pw, *pw2;
- har cmsname[CMS_NAMESIZE];
- _char red[256], green[256], blue[256];
-
- #ifdef STANDALONE
- ain(argc, argv, envp)
- #else
- inlev8_main(argc, argv, envp)
- #endif
- int argc;
- char **argv;
- char **envp;
-
- {
- int i, j, x, y;
- u_char *pi;
- char *makelabel();
-
- progname = strsave(argv[0]);
- parse_profile(&argc, argv, envp);
-
- while ((gc = getopt(argc, argv, " ")) != EOF)
- switch (gc) {
- case '?':
- errflag++;
- break;
- }
-
- if (errflag)
- error((char *) 0, "Usage: %s:\n", progname);
-
- if ((font = pf_open(WINLEVFONT)) == NULL) {
- fprintf(stderr, "%s : Cannot open %s\n", argv[0], WINLEVFONT);
- exit(1);
- }
- boxsize = 1;
-
- /* Initialise variables used to set colour map segment */
- for (i = 0; i < 256; i++) {
- red[i] = i;
- green[i] = i;
- blue[i] = i;
- }
- if (mono_override) {
- red[0] = blue[0] = green[0] = 255;
- red[254] = blue[254] = green[254] = 255;
- red[255] = blue[255] = green[255] = 0;
- }
-
- /* create frame and canvas */
- frame = window_create(NULL, FRAME,
- FRAME_LABEL, makelabel(),
- WIN_HEIGHT, YSIZE * boxsize + 78 + base,
- WIN_WIDTH, XSIZE * boxsize + 10,
- FRAME_ICON, &icon,
- FRAME_ARGS, argc, argv,
- 0);
-
- panel = window_create(frame, PANEL, 0);
-
- inv_panel = panel_create_item(panel, PANEL_CYCLE,
- PANEL_CHOICE_STRINGS, "Normal", "Inv", 0,
- PANEL_NOTIFY_PROC, invert_proc,
- 0);
- col_panel = panel_create_item(panel, PANEL_CYCLE,
- PANEL_CHOICE_STRINGS, "Grey", "Col", 0,
- PANEL_NOTIFY_PROC, colour_proc,
- 0);
- panel_create_item(panel, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, panel_button_image(panel, "Reset", 0, 0),
- PANEL_NOTIFY_PROC, reset_proc,
- 0);
- panel_create_item(panel, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, panel_button_image(panel, "Quit", 0, 0),
- PANEL_NOTIFY_PROC, quit_proc,
- 0);
-
- window_fit(panel);
- window_set(panel, WIN_WIDTH, XSIZE, 0);
-
- canvas2 = window_create(frame, CANVAS,
- WIN_BELOW, panel,
- WIN_X, 0,
- WIN_WIDTH, XSIZE,
- WIN_HEIGHT, 10,
- 0);
- pw2 = canvas_pixwin(canvas2);
-
- /* Set colour map segment */
- pw_setcmsname(pw2, "greyscale8");
- pw_putcolormap(pw2, 0, 256, red, green, blue);
- draw_ramp();
-
- canvas = window_create(frame, CANVAS,
- WIN_BELOW, canvas2,
- WIN_X, 0,
- WIN_EVENT_PROC, getcoords,
- 0);
-
- /* get the canvas pixwin to draw into */
- pw = canvas_pixwin(canvas);
-
- /* Set colour map segment */
- pw_setcmsname(pw, "greyscale8");
- pw_putcolormap(pw, 0, 256, red, green, blue);
-
- window_set(canvas, WIN_CONSUME_PICK_EVENTS, LOC_DRAG, 0, 0);
-
- pw_vector(pw, 0, 255, 255, 255, PIX_SRC, 255);
- pw_vector(pw, 127, 255, 127, 0, PIX_SRC, 255);
- pw_vector(pw, 0, 255, 255, 0, PIX_SRC, 255);
- pw_vector(pw, 255, 255, 0, 0, PIX_SRC, 255);
- pr_text(pw->pw_prretained, 0, 128, PIX_SRC, font, "Window");
- pr_text(pw->pw_prretained, 108, 250, PIX_SRC, font, "Level");
-
- window_main_loop(frame);
- }
-
- tatic void
- nvert_proc(item, value, event)
- Panel_item item;
- int value;
- Event *event;
- {
- invert = value;
- setupcolourmap();
- }
-
- tatic void
- olour_proc(item, value, event)
- Panel_item item;
- int value;
- Event *event;
- {
- colour = value;
- setupcolourmap();
- }
-
-
- tatic void
- etcoords(canvas, event, arg)
- Canvas canvas;
- Event *event;
- caddr_t arg;
- {
- char *makelabel();
-
- if ((event_id(event) == LOC_DRAG)
- || (event_id(event) == MS_LEFT)
- || (event_id(event) == MS_RIGHT)
- || (event_id(event) == MS_MIDDLE)) {
- window = (255 - event_y(event)) * 2; /* allows double window
- * if desired */
- window = (window < 0) ? 0 : window;
- level = event_x(event);
-
- setupcolourmap();
- window_set(frame, FRAME_LABEL, makelabel(), 0);
- }
- }
-
- etupcolourmap()
- {
- int col, i;
- double m;
-
- /* Initialise variables used to set colour map segment */
- for (i = 0; i < 256; i++) {
- if (window) {
- m = 256.0 / window;
- col = m * (i - level) + 127;
- } else
- col = (i < level) ? 0 : 255;
- col = (col < 0) ? 0 :
- (col > 255) ? 255 : col;
- col = (invert) ? 255 - col : col;
- if (colour) {
- getrgb(col, &red[i], &green[i], &blue[i]);
- } else {
- red[i] = col;
- green[i] = col;
- blue[i] = col;
- }
- }
- if (mono_override) {
- red[0] = green[0] = blue[0] = 255;
- /*red[254] = blue[254] = green[254] = 255;*/
- red[255] = blue[255] = green[255] = 0;
- }
- pw_putcolormap(pw, 0, 256, red, green, blue);
- pw_putcolormap(pw2, 0, 256, red, green, blue);
- }
-
- har *
- akelabel()
- {
- static char buf[BUFSIZ];
- char *sprintf();
-
- return sprintf(buf, "Window = %3d Level = %3d", window, level);
- }
-
- etrgb(val, r, g, b)
- int val;
- u_char *r, *g, *b;
- {
- static float coltab[48][3] = {
- 1.0, 1.0, 1.0,
- 1.0, 0.75, 0.75,
- 1.0, 0.5, 0.5,
- 1.0, 0.25, 0.25,
- 1.0, 0.0, 0.0,
- /* 1.0, 0.064, 0.0, */
- 1.0, 0.193, 0.0,
- 1.0, 0.258, 0.0,
- 1.0, 0.323, 0.0,
- 1.0, 0.387, 0.0,
- 1.0, 0.452, 0.0,
- 1.0, 0.516, 0.0,
- 1.0, 0.548, 0.0,
- 1.0, 0.613, 0.0,
- 1.0, 0.677, 0.0,
- 1.0, 0.742, 0.0,
- 1.0, 0.806, 0.0,
- 1.0, 0.871, 0.0,
- 1.0, 0.936, 0.0,
- 1.0, 1.0, 0.0,
- 0.903, 1.0, 0.0,
- 0.806, 1.0, 0.0,
- 0.677, 1.0, 0.0,
- 0.516, 1.0, 0.0,
- 0.0, 1.0, 0.452,
- 0.0, 1.0, 0.710,
- 0.0, 1.0, 1.0,
- 0.0, 0.871, 1.0,
- 0.0, 0.677, 1.0,
- 0.0, 0.613, 1.0,
- 0.0, 0.548, 1.0,
- 0.0, 0.484, 1.0,
- 0.0, 0.419, 1.0,
- 0.0, 0.355, 1.0,
- 0.0, 0.290, 1.0,
- 0.0, 0.226, 1.0,
- 0.0, 0.161, 1.0,
- 0.0, 0.0, 1.0,
- 0.516, 0.0, 1.0,
- 0.581, 0.0, 1.0,
- 0.645, 0.0, 1.0,
- 0.710, 0.0, 1.0,
- 0.774, 0.0, 1.0,
- 0.839, 0.0, 1.0,
- 0.903, 0.0, 1.0,
- 0.968, 0.0, 1.0,
- 1.0, 0.0, 0.935,
- 1.0, 0.0, 0.839,
- 1.0, 0.0, 0.742
-
- /*
- * 1.0, 0.0, 0.613, 1.0, 0.0, 0.484, 1.0, 0.0, 0.097
- */
- };
-
- int val48;
- float rval48, roffset;
- float rr, rg, rb;
-
- rval48 = val / 5.426;
- val48 = rval48;
- roffset = rval48 - (float) val48;
-
- rr = (coltab[val48][0] * (1.0 - roffset) + coltab[val48 + 1][0] * roffset);
- rg = (coltab[val48][1] * (1.0 - roffset) + coltab[val48 + 1][1] * roffset);
- rb = (coltab[val48][2] * (1.0 - roffset) + coltab[val48 + 1][2] * roffset);
- *r = ((rr * 0.9 + 0.1) * 255.0 + 0.5);
- *g = ((rg * 0.85 + 0.15) * 255.0 + 0.5);
- *b = ((rb * 0.9 + 0.1) * 255.0 + 0.5);
- }
-
- tatic void
- uit_proc()
- {
- window_set(frame, FRAME_NO_CONFIRM, TRUE, 0);
- window_destroy(frame);
- }
-
- tatic void
- eset_proc()
- {
- window = 255;
- level = 127;
- invert = 0;
- colour = 0;
- panel_set_value(inv_panel, invert);
- panel_set_value(col_panel, colour);
- setupcolourmap();
- window_set(frame, FRAME_LABEL, makelabel(), 0);
- }
-
- raw_ramp()
- {
- register i;
-
- for (i = 0; i < XSIZE; i++)
- pw_vector(pw2, i, 0, i, 10, PIX_SRC, i);
- }
-